package com.ruoyi.system.xcenter;

import com.ruoyi.system.domain.DataxEndGroup;
import com.ruoyi.system.domain.DataxEndPoint;
import com.ruoyi.system.mapper.DataxEndGroupMapper;
import com.ruoyi.system.mapper.DataxEndPointMapper;
import com.ruoyi.system.xcenter.adapter.Jieshun2XindianAdapter;
import com.ruoyi.system.xcenter.adapter.Xiwo2XindianAdapter;
import com.ruoyi.system.xcenter.endpoints.JieshunEndPoint;
import com.ruoyi.system.xcenter.endpoints.XindianEndPoint;
import com.ruoyi.system.xcenter.endpoints.XiwoEndPoint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class PassiveChangeConfig {

    @Autowired
    private DataxEndGroupMapper groupMapper;
    @Autowired
    private DataxEndPointMapper endPointMapper;
    @Autowired
    private JieshunEndPoint jieshunEndPoint;
    @Autowired
    private XindianEndPoint xindianEndPoint;
    @Autowired
    private Jieshun2XindianAdapter jieshun2XindianAdapter;
    @Autowired
    private Xiwo2XindianAdapter xiwo2XindianAdapter;
    @Autowired
    private XiwoEndPoint xiwoEndPoint;

    @PostConstruct
    public void init(){
        // 捷顺推送数据>中转处理>入库信电
        EPContext context = contextInitByGroupID(1);
        EPContext xiwoContext = contextInitByGroupID(2);
        jieshunEndPoint.registryEndPoint(xindianEndPoint,context,jieshun2XindianAdapter);
        xiwoEndPoint.registryEndPoint(xindianEndPoint,xiwoContext,xiwo2XindianAdapter);
//        xindianEndPoint.init(context);
    }

    private EPContext contextInitByGroupID(Integer id){
        EPContext context = new EPContext();
        DataxEndGroup dataxEndGroup = groupMapper.selectDataxEndGroupById(id.longValue());
        DataxEndPoint client = endPointMapper.selectDataxEndPointById(dataxEndGroup.getEndClient());
        DataxEndPoint platform = endPointMapper.selectDataxEndPointById(dataxEndGroup.getEndPlatform());

        context.setClient(client);
        context.setPlatform(platform);
        context.setDataxEndGroup(dataxEndGroup);

        return context;
    }
}
